package com.sngamelib.topdownshooter;

import java.util.ArrayList;
import java.util.Iterator;

public class Group<_T> extends Thread
{
	private ArrayList<_T> ItemList;
	private int maxGroupSize;  //if zero/null group has no max size otherwise group cannot grow beyond this limit
	
	Group()
	{
		ItemList = new ArrayList<_T>();
		maxGroupSize = 0;
	}
	
	Group(double _mgs)
	{
		ItemList = new ArrayList<_T>();
		maxGroupSize = (int)_mgs;
	}
	
	Group(int _arSize)
	{
		ItemList = new ArrayList<_T>();
		maxGroupSize = 0;
		ItemList.ensureCapacity(_arSize);
	}
	
	Group(int _arSize, int _mgs)
	{
		ItemList = new ArrayList<_T>();
		maxGroupSize = _mgs;
		if(_arSize > maxGroupSize)
			ItemList.ensureCapacity(maxGroupSize);
		else
			ItemList.ensureCapacity(_arSize);
	}
	
	Group(_T _t)
	{
		ItemList = new ArrayList<_T>();
		ItemList.add(_t);
		maxGroupSize = 0;
	}
	
	Group(_T _t, int _mgs)
	{
		ItemList = new ArrayList<_T>();
		maxGroupSize = _mgs;
		ItemList.add(_t);
	}
	
	Group(ArrayList<_T> _il)
	{
		ItemList = new ArrayList<_T>(_il);
		maxGroupSize = 0;
	}
	
	Group(ArrayList<_T> _il, int _mgs)
	{
		ItemList = new ArrayList<_T>();
		maxGroupSize = _mgs;
		while(ItemList.size() < maxGroupSize)
		{
			ItemList.add(_il.get(ItemList.size()-1));
		}
	}
	

	public _T Get(_T _t)
	{
		Iterator<_T> itr = ItemList.iterator();
		while (itr.hasNext())
		{
			 if(itr.equals(_t))
			 {
				 return (_T)itr.getClass();
			 }
		}
		
		_T retVal = null;
		return retVal;
	}
	
	public _T Get(int _i)
	{
		return ItemList.get(_i);
	}
	
	public int Add(_T _t)
	{
		if(ItemList.size() < maxGroupSize)
			ItemList.add(_t);
		
		return ItemList.size()-1;
	}
	
	public void Set(int _index, _T _t)
	{
		ItemList.set(_index, _t);
	}
	
	public boolean Remove(_T _t)
	{
		return ItemList.remove(_t);
	}
	
	public boolean RemoveAt(int _i)
	{
		_T removed = ItemList.remove(_i);
		if (removed != null)
			return true;
		else
			return false;
	}
	
	public int getSize()
	{
		return ItemList.size();
	}
	
	public int getMaxGroupSize()
	{
		return maxGroupSize;
	}
	
	public void setSize(int _size)
	{
		if(_size <= maxGroupSize)
			ItemList.ensureCapacity(_size);
		else
			ItemList.ensureCapacity(maxGroupSize);
	}
	
	public void setMaxGroupSize(int _size)
	{
		maxGroupSize = _size;
	}
	
	
	@Override
	public void run()
	{
		// TODO Auto-generated method stub

	}


}
